<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Éditions de la plus haute tour</title>

    <!-- Bootstrap Core CSS -->
    <link href="<?php echo base_url();?>public/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="<?php echo base_url();?>public/css/css.css" rel="stylesheet">
    <link href="<?php echo base_url();?>public/css/tabcss.css" rel="stylesheet">
     <link href="<?php echo base_url();?>public/css/validate.css" rel="stylesheet">
    <!-- Fonts -->
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
         .idPass p,.idEmail p{
            color: red;
         }
         
    </style>

</head>

<body>

    <div class="brand">Éditions de la plus haute tour </div>
    <!-- <div class="address-bar">3481 Melrose Place | Beverly Hills, CA 90210 | 123.456.7890</div>
 -->
    <!-- Navigation -->
    <nav class="navbar navbar-default" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Menu</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <!-- navbar-brand is hidden on larger screens, but visible when the menu is collapsed -->
                <a class="navbar-brand" href="index.html">Éditions de la plus haute tour</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">                
                      <li>                       
                        <?php echo anchor(base_url(),"Accueil"); ?>
                    </li>
                    <li>                       
                        <?php echo anchor("book/books","Livres"); ?>
                    </li>
                  <!--   <li>                       
                        <?php echo anchor("book/howToBuy","Pre-Commande"); ?>
                    </li> -->
                    <li>                       
                        <?php echo anchor("book/about","Qui sommes-nous?"); ?>
                    </li>
                    <li>
                        <?php echo anchor("book/blog","Blog"); ?>
                    <li>
                        <?php echo anchor("book/contact","Contact"); ?>
                    </li>
                    

                     <li class="dropdown">
                        <?php 

                            if(!$this->cart->contents()){
                                $cartItem = "0";
                            }else{
                               $cartItem = count($this->cart->contents());
                            }
                            echo anchor("book/viewCart",'<span class="glyphicon glyphicon-shopping-cart icon_cart"></span> (<span class="icon_cart">'.$cartItem.'</span>)');
                            
                        ?>


                      
                       <!--  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <span class="glyphicon glyphicon-shopping-cart icon_cart"></span> (<span class="icon_cart"><?php  $cartItem; ?></span>) </a> -->
                            <!-- <ul class="dropdown-menu dropdown-cart" role="menu"> -->
                     <?php
                            
                             
                            //$this->load->view('book/cart');
                      ?>
                       <!--  </ul> -->
                    
                    </li>

                    <li>
                        



                         <?php
             if($this->session->userdata("loggedIn")){

        
                echo '<li><a href="">'.$this->session->userdata("username").'</a></li>';
                echo '<li>'.anchor("book/logout","Logout").'</li>';
             }
         ?>


                    </li>


                </ul>
               
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    <div class="container">

        <div class="row background-white">
                 

            <?php
                if(isset($page)){
                    $this->load->view("book/".$page);
                }
             ?>
              
        </div>

    </div>
    <!-- /.container -->

  <footer>
        <div class="container">
            <div class="row">
             <!--    <div class="col-lg-12 text-center">
                    <p></p>
                </div> -->
            </div>
        </div>
    </footer> 

    <!-- jQuery -->
    <script src="<?php echo base_url();?>public/js/jquery.js"></script>
    <script src="<?php echo base_url();?>public/js/validate.js"></script>
    <script src="<?php echo base_url();?>public/js/method_addtional.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="<?php echo base_url();?>public/js/bootstrap.min.js"></script>


<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.3";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

	<script type="text/javascript">

        jQuery.validator.setDefaults({
          debug: true,
          success: "valid"
        });
        $("#idOrderInfo").validate({
            rules:{
                contactName:{
                     required: true
                },
                country:{
                     required: true
                },
                street:{
                      required: true
                },
                city:{
                    required: true
                },
                province:{
                     required: true
                 },
                 postOfficeId:{
                    required: true
                 },
                sipCode:{
                    required: true
                },
                mobile:{
                    required: true
                }

            },
            submitHandler: function(form)
            {
                form.submit();
            }
        });
		$("#formRegisterInfo").validate({
			rules: {
            txtpass: {
              required: true,
			  minlength : 5,
              
            },
            txtconfirmpass:{
                required: true,
				minlength : 5,
                equalTo : "#password"
            },
			 txtfname: {
              required: true,
              
            },
            txtlname:{
                required: true,
				
            }
           
          },
          submitHandler: function(form)
             {
				form.submit();
			}
		});


        $(".addNewCustomerShippig").validate({
            rules: {
                txtfname: {
                  required: true
                  
                },
                email:{
                    required: true,
                    email: true
                },
                password: {
                  required: true,
                  minlength : 5
                  
                },
                passwordConfirm:{
                    required: true,
                    minlength : 5,
                    equalTo : "#password"
                }
             
            
           
          },
          submitHandler: function(form)
             {
                form.submit();
            }
        });

//         $(".formShippingAddess").validate({
//             rules: {
//                 contactName: {
//                   required: true
                  
//                 },
//                 country:{
//                     required: true
//                 },
//                 street:{
//                     required: true
//                 },
//                  city:{
//                     required: true
//                 },
//                  city:{
//                     required: true
//                 },
//                  province:{
//                    required: true 
//                },
//                  sipCode:{
//                 required: true 
//                 },
//                  mobile:{
//                    required: true   
//                 }

           
//           },
//           submitHandler: function(form)
//              {
//                 $(".formShippingAddess").submit();
//             }
//         });



        $( "#formRegisterEmail" ).validate({
          rules: {
            email: {
              required: true,
              email: true
            },
            agree:{
                required: true,
            }
           
          },
          submitHandler: function(form)
             {
            var mail = $("input[name=email]").val();
           
                  $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>index.php/book/checkMailExit",
                    data :{email:mail},
                    success: function(response) {
                        if(response == 1){
                            $(".emailExit").html("<label class='error'></label>An account already exists with the E-mail you submitted, please change an E-mail address or Login.");
                        }else{
                             form.submit();
                        }
                    }
                 }); 
               
             }
        });
            $(function(){
        $('a[title]').tooltip();
        });

	   $(document).ready(function() { 
        /*place jQuery actions here*/ 
        var link = "<?php echo base_url();?>index.php/"; // Url to your application (including index.php/)
       

        $("#formAddCard").submit(function() {
            // Get the product ID and the quantity 
            var id = $(this).find('input[name=postId]').val();
            var qty = $(this).find('input[name=qty]').val();
            var price = $(this).find('input[name=price]').val();
            var img = $(this).find('input[name=img]').val();
            var name = $(this).find('input[name=bookName]').val();
            var shipping = $(this).find('input[name=shipping]').val();
            $.post(link + "book/addCart", { postId: id, qty: qty, price: price, img: img, name: name,shipping:shipping},
                function(data){ 
                   if(data == '1'){
                    location.reload();
                   }  
             });
            return false; 
        });

        $("body").on("click","#btnBuyNow",function() {

            var id = $('input[name=postId]').val();
            var qty = $('input[name=qty]').val();
            var price = $('input[name=price]').val();
            var img = $('input[name=img]').val();
            var name = $('input[name=bookName]').val();
            var shipping = $('input[name=shipping]').val();
            
             $.post(link + "book/addCart_BuyOne",$("#formAddCard").serialize() ,
                function(data){ 
                   if(data == '1'){
                    window.location = "<?php echo base_url();?>index.php/book/orderCard";
                   }  
             });
            return false; 
        });


        $("body").on('click',".removeCard",function(event){
            var id = $(this).val();
             $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>index.php/book/removeCard",
                    data :{id:id},
                    success: function(response) {
                        location.reload();
                    }
                });   
        });
      

        // $("#formRegisterEmail").submit(function(){

        //      $.post($("#formRegisterEmail").attr("action"),$("#formRegisterEmail").serialize(),function(json){
        //         if(json['st'] == 0){

        //             $(".idEmail").html(json['email']);
        //         }
        //      },'json');
        //     return false;
        // });

        // $("#idEmailRegister").on("keypress keyup change",function(){
            
        //     var value = $(this).val();
        //     if(value !=""){
        //          $(".idEmail").html("");
        //     }else{
        //         $(".idEmail").html("<p>Please enter your email!</p>");
               
        //     }
        // });
           
        // $(".addNewAddess").click(function(){
        //     $("#formShippingAddess").css("display","block");
        //     $('#formShippingAddess').attr('action', "<?php echo base_url(); ?>index.php/book/addNewShippingAddess");
        //     $(".contactName").val("");
        //     $(".countryId").val("");
        //     $(".streetAddess").val("");
        //     $(".apartmentName").val("");
        //     $(".cityName").val("");
        //     $(".provinceName").val("");
        //     $(".shipcode").val("");
        //     $(".mobileNum").val("");
        //     $(".shippingId").val("");

        //     $(".saveBtnShipping").val("Save");
        // });
        

        $("body").on('click',"#newCustomer",function(){
            $("#passOldText").attr("disabled","disabled");
        });
         $("body").on('click',"#oldCustomer",function(){
            $("#passOldText").removeAttr("disabled","disabled");
        });
        
       // $(".selectOtherAddess").click(function(event){
       //       $(".adressShipping").addClass('showMoreAddess');
       //       $(".adressShipping").removeClass('hideShippingAddess');

       // });
        // $("input:radio[name=userOrderShipping]").click(function() {
        //     var value = $(this).val();
           
        //     $("input[name=userOrderId]").val(value);
        // });

        // $(".selectOtherAddess").click(function(event){
            
        //      var html = ""; 
        //      var href = $(this).attr("href");
        //       $.ajax({
        //         type: "GET",
        //         url: href,
        //         success: function(response) {
                  
        //             $.each(response, function(key, value) {
        //                 html += '<div class="form-group divBorder">';
        //                 html += '<p><b><input type="radio" name="userOrderShipping" value="'+value['orderUId']+'" /> '+value['fullname']+'</b><br/>';
        //                 html +=   value['street']+'<br/>';
        //                 html +=  value['city']+', '+value['province']+', '+value['sipCode'];
        //                 html += '<br/>'+value['country_name'];
        //                 html += '<br/> Mobile  : '+value['mobile'];
        //                 html += '</p>';
        //                 html += '<p>';
        //                 html += '<a href="<?php echo base_url();?>index.php/book/getDetailShipping/'+value['orderUId']+'" class="editShipping"><span class="label label-primary">Edit</span></a>&nbsp;&nbsp;';
        //                 html += '<a href="<?php echo base_url();?>index.php/book/deleteDetailShipping/'+value['orderUId']+'" ><span class="label label-danger">Delete</span></a>';
                        
        //                 html += '</p>';
        //                 html += '</div>';
        //                 $("#showMoreAddess").html(html);
        //             });
        //         }
        //       });
        //      event.preventDefault();
        // });
        
        $("body").on('click',".editShipping",function(event){
            

            var href = $(this).attr("href");
              $.ajax({
                type: "GET",
                url: href,
                success: function(response) {
                  

                  $('.formShippingAddess').attr('action', "<?php echo base_url(); ?>index.php/book/updateShippingAddess");
                  $("form.formShippingAddess").removeClass("formShippingAddess");
                  $(".contactName").val(response['fullname']);
                  $(".countryId").val(response['countryid']);
                  $(".streetAddess").val(response['street']);
                  $(".apartmentName").val(response['apartment']);
                  $(".cityName").val(response['city']);
                  $(".provinceName").val(response['province']);
                  $(".shipcode").val(response['sipCode']);
                  $(".mobileNum").val(response['mobile']);
                  $(".shippingId").val(response['orderUId']);
                  $(".saveBtnShipping").val("Update");
                }
              });
             event.preventDefault();
        });
        


        $( ".formLoginShipping" ).validate({
          rules: {
            email: {
              required: true,
              email: true
            },
            password:{
                required: true,
            }
          },
          submitHandler: function(form)
             {
                form.submit();
             }
        });

        $(".formLogin").submit(function(){
            alert("hello");
            $.post($(".formLogin").attr("action"),$(".formLogin").serialize(),function(json){
                if(json['st'] == 0){
                    $(".idEmail").html(json['email']);
                    $(".idPass").html(json['password']);
                }else if(json['st'] == 1){
                    $(".idPass").html(json['error']);
                    $("#passCard").val("");
                    $(".idEmail").html("");
                }else{
                    window.location = "<?php echo base_url();?>index.php/book/orderCard";
                }
            },'json');
            return false;
        });
    });
	</script>

     <?php 
   
        if($this->uri->segment(2) != "orderCard" | $this->uri->segment(2) != "register"){
            $this->session->unset_userdata("registerInfor");
			$this->session->unset_userdata("register_process");
			$this->session->unset_userdata("usermail");
        }
		
		?>
</body>

</html>
